import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../components/index.vue'
import SelectAddress from '../components/SelectAddress.vue'
import HomeHt from'../components/HomeHt.vue'
import WelCome from '../components/Welcome.vue'
import UserHt from '../components/UserHt.vue'
import AdminHt from '../components/AdminHt.vue'
import StudentHt from '../components/StudentHt.vue'
import AddressHt from '../components/AddressHt.vue'
import AfficheHt from '../components/AfficheHt.vue'
import Main from '../components/Main.vue'
import Problem from '../components/Problem.vue'
import Notice from '../components/Notice.vue'
import Download from "../components/Download.vue"
import UserInfo from "../components/UserInfo.vue"
import Register from "../components/Register.vue"
import BaoMing from "../components/BaoMing.vue"
import ProblemHt from "../components/ProblemHt.vue"
/*用户登录组件*/
import UserLogin from '../components/UserLogin.vue'
import Test from '../components/test.vue'


Vue.use(VueRouter)

const routes = [
   {path: "/", redirect:"/index"},
   {path: '/baoming',component: BaoMing},
  //前台
    {path: '/index', component:Index,redirect:'/main',children: [
        {path: "/main",component: Main,redirect:'/problem1',children:[
            {path: "/problem1",component: Problem},
            {path: "/problem2",component: Problem},
            {path: "/problem3",component: Problem},
            {path: "/test",component: Test},
			
            ]},
        {path: "/problema",component: Problem},
        {path: "/problemb",component: Problem},
        {path: "/problemc",component: Problem},
        {path: "/download",component: Download},
        {path: "/notice",component: Notice},
        {path: '/center',component: UserInfo,redirect:'/address2',children:[{path: '/address2',component: SelectAddress}]},
      ]},
	  {path: "/login",component: UserLogin},
      {path: '/register',component: Register,redirect:'/address1',children:[
         {path: '/address1',component: SelectAddress}
      ]},
  //后台
  {path: '/homeHt',component: HomeHt,redirect:'/Welcome',children:[
  	  {path: '/Welcome',component: WelCome},
	  {path: '/userHt',component: UserHt},
	  {path: '/adminHt',component: AdminHt},
	  {path: '/studentHt',component: StudentHt},
	  {path: '/addressHt',component: AddressHt},
	  {path: '/afficheHt',component: AfficheHt},
    {path: '/problemHt',component: ProblemHt}
  ]}
]

const router = new VueRouter({
  routes
})
// 定义路由守卫，判断如果非/login之外的 请求，没有登录，则默认跳转登录页面取登录
// router.beforeEach((to, from, next) => {
//     // 判断如果是/login，则释放
//     if ((to.path == '/') || (to.path == '/login') || (to.path == '/index') ||(to.path == '/main') || (to.path == '/problem1')|| (to.path == '/register') || (to.path == '/address1')) {
//         return next();
//     }
//     //判断如果sessionStroy中没有数据，则为未登录，跳转到取登录的页面
//     var token = window.sessionStorage.getItem("token")
//     if (!token) { //没有数据
//         return next('/login')  // 如果token值没有，则跳转到 login页面
//     }
//     next();  // 进入你的请求中
// })

export default router
